{% extends 'course/base.html' %}
{% load staticfiles %}
{% block content %}
<!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Credit <small>Get credit for completing this course!</small>
                </h1>
                
                <ol class="breadcrumb">
                    <li>
                        <i class="fa fa-university"></i>  <a href="/courses">Courses</a>
                    </li>
                    <li>
                        <i class="fa fa-compass"></i> {{ course.title }}
                    </li>
                    <li class="active">
                        <i class="fa fa-home"></i> Home
                    </li>
                </ol>
            </div>
        </div>
        <!-- /.row -->

        {% if final_mark == None %}
        
        <!-- Apply Now Banner Row -->
        <div class="jumbotron">
            <h1>Get Credit</h1>
            <p>You can apply to get credit for having completed this course. Once the credit has been granted, you can:</p>
            <p><b>Share</b> with employers, teachers and friends that you've succeeded in completing this course.</p>
            <p><b>Track</b> what you've learned so you'll know where you are going with your education.</p>
            <p><a onclick="ajax_submit_credit_application();"
                       id="submit_credit_app_btn"
                     name="submit_credit_app_btn"
                    class="btn btn-primary btn-lg"
                     role="button">Apply Now »</a>
            </p>
        </div>
        <!-- /.row -->
        
        {% else %}
        
        <!-- Credit Granted Banner Row -->
        <div class="jumbotron">
            <h1>Credit Granted</h1>
            <p>Congradulations, you have been granted full credit for completing this class!</p>
            <p>We hope you enjoyed this course.</p>
        </div>
        <!-- /.row -->
        
        {% endif %}
<script>
    function ajax_submit_credit_application()
    {
        $('#submit_credit_app_btn').prop("disabled", true);
        $.ajax( 'submit_credit_application', {
           data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
           },
           type: 'post',
           success: function(result) {
               // success code execution here
               if (result.status == 'success')
               {
                    window.location = ""; // Refresh page.
               }
               else
               {
                    alert(result.message);
               }
           },
           error: function(xhr,status,error) {
                // error code here
           },
           complete: function(xhr,status) {
               // completion code here
               $('#submit_credit_app_btn').prop("disabled", false);
           }
        });
    }
</script>
{% endblock content %}
